echo "执行脚本"
# ./build.sh v1.0.0

echo "获取版本号"
VERSION=${1}

# "这些是我们希望传递给Version和BuildTime的值"
GITHASH=`git rev-parse HEAD 2>/dev/null`

BUILDAT=`date +%FT%T%z`

# "此处在此处为go build设置-ldflags选项，插值变量值"
LDFLAGS="-s -w -X github.com/TruthHun/BookStack/utils.GitHash=${GITHASH} -X github.com/TruthHun/BookStack/utils.BuildAt=${BUILDAT} -X github.com/TruthHun/BookStack/utils.Version=${VERSION}"

echo "开始构建:" ${VERSION}
rm -rf release/${VERSION}
mkdir -p release/${VERSION}

echo "构建mac版本"
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -o release/${VERSION}/mac/BookStack -ldflags "${LDFLAGS}"
echo "构建linux版本"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o release/${VERSION}/linux/BookStack -ldflags "${LDFLAGS}"
echo "构建windows版本"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o release/${VERSION}/windows/BookStack.exe -ldflags "${LDFLAGS}"

echo "压缩mac版本"   
upx -f -9 release/${VERSION}/mac/BookStack
echo "压缩linux版本"
upx -f -9 release/${VERSION}/linux/BookStack
echo "压缩windows版本"
upx -f -9 release/${VERSION}/windows/BookStack.exe

echo "复制配置文件"
cp -r conf release/${VERSION}/mac/
cp -r conf release/${VERSION}/linux/
cp -r conf release/${VERSION}/windows/

echo "复制视图文件"
cp -r views release/${VERSION}/mac/
cp -r views release/${VERSION}/linux/
cp -r views release/${VERSION}/windows/

echo "复制词典文件"
cp -r dictionary release/${VERSION}/mac/
cp -r dictionary release/${VERSION}/linux/
cp -r dictionary release/${VERSION}/windows/

echo "复制静态文件"
cp -r static release/${VERSION}/mac/
cp -r static release/${VERSION}/linux/
cp -r static release/${VERSION}/windows/